package main

import (
	"context"
	"fmt"
	"go.etcd.io/etcd/clientv3"
	"time"
)

func main() {
	var(
		config clientv3.Config  // 客户端配置
		client *clientv3.Client // 客户端
		err error
		kv clientv3.KV          // kv客户端
		op clientv3.Op
		opResp clientv3.OpResponse
	)
	// 配置
	config = clientv3.Config{
		Endpoints:[]string{"127.0.0.1:2379"},
		DialTimeout:5*time.Second,
	}

	// 连接客户端
	if client,err = clientv3.New(config);err != nil{
		fmt.Println(err)
		return
	}

	kv = clientv3.NewKV(client)

	// OpPut
	op = clientv3.OpPut("/cron/jobs/job8","this is 4.trylock 8")
	if opResp,err = kv.Do(context.TODO(),op);err!=nil{
		fmt.Println(err)
		return
	}
	fmt.Println("写入版本:",opResp.Put().Header.Revision)

	// OpGet
	op = clientv3.OpGet("/cron/jobs/job8")
	if opResp,err = kv.Do(context.TODO(),op);err!=nil{
		fmt.Println(err)
		return
	}
	fmt.Println("获取值:",string(opResp.Get().Kvs[0].Value))
	fmt.Println("获取ModRevision:",opResp.Get().Kvs[0].ModRevision)

	//

}
